﻿<%@ Control Language="VB" AutoEventWireup="false" CodeFile="SF_INPUT.ascx.vb" Inherits="WebForm_ManageSalesWorkingFile_SF_INPUT" %>
<%@ Register Src="~/WebForm/ManageSalesForecast/SearchOption.ascx" TagName="ProductHierarchyControl"
    TagPrefix="My" %>
<%@ Register Namespace="MyReport" TagPrefix="cc1" %>
<%@ Register Assembly="System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" Namespace="System.Web.UI" TagPrefix="cc2" %>
<asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server">
    <Services>
        <asp:ServiceReference Path="~/WebForm/ManageSalesForecast/SFService.asmx" />
        <asp:ServiceReference Path="~/WebForm/BLSService.asmx" />
    </Services>
</asp:ScriptManagerProxy>
<%--<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>--%>

<script type="text/javascript">
    var StartColumn = "F1";//預設起始欄位
    function <%=Me.ClientID %>SF_FindProd() {
        var sheet = $get('WF_Spreadsheet1');
        var txtFindProd = $get('<%=Search2.FindControl("txtFindProd").ClientID %>');
        var hf_FindProd = $get('<%=hf_FindProd.ClientID %>');
        var targetcell = sheet.ActiveCell.Row >= 4 && sheet.ActiveCell.Column <= 5 ? sheet.ActiveCell : sheet.Range('A' + sheet.ActiveSheet.Rows.Count);

        if (txtFindProd.value == '') {
            alert('Please enter Keyword!!');
            return;
        }

        if (hf_FindProd.value != txtFindProd.value) {
            hf_FindProd.value = txtFindProd.value;
        }

        //設定需要搜尋的欄位區間
        var ssConstants = sheet.Constants;
        var r = sheet.Range('A4:E' + sheet.ActiveSheet.Rows.Count);

        var fndCell = r.Find(txtFindProd.value, targetcell, ssConstants.xlValues, ssConstants.xlPart, ssConstants.xlByRows);

        if (fndCell == null) {
            alert('No more matched Keyword!!');
        }
        else {
            fndCell.Select();
            fndCell.Activate();
        }
    }

    function openSpecWindow(sType) {
        if (sType == 'Percentage') {
            var url = '<%= ResolveUrl("~/WebForm/CustomerGroupPercentageQuery.aspx") %>' + '?SessionID=<%=Me.SessionID %>';
            window.open(url, '', OpenInCenter(400, 350) + ',toolbar=0,titlebar=0,resizable,scrollbars=Yes,status=1');
        }
    }

    function <%=Me.ClientID %>YearNext(n) {
        var sheet = $get('WF_Spreadsheet1');
        var txtDailyInputYear = $get('<%=Search2.FindControl("txtDailyInputYear").ClientID %>');
        var result = Number(txtDailyInputYear.value) + n;

        //var now=new Date();
        //var i = now.getFullYear();
        var i = '<%=Me.SFModel.SF_Year %>';
        if ('<%=Me.SFModel.SF_Month %>' == 'B') {
            var now = new Date(i, 1, 1);
            var mydate = new Date(i, 1, 1);
        }
        else {
            var now = new Date(i, '<%=Me.SFModel.SF_ReferMM %>', 1);
            var mydate = new Date(i, '<%=Me.SFModel.SF_ReferMM %>', 1);
        }
        var finalresult = result - i;
        //var mydate = new Date();

        mydate.setMonth(now.getMonth() + 15);

        if (result > mydate.getFullYear() || result < i - 1) {
            alert("It's out of range!");
        }
        else {

            switch (finalresult) {
                //前一年的Act改用Pop Window顯示,Update By Angus 20101117
                case -1:
                    $get('<%=Search2.FindControl("txtDailyInputYear").ClientID %>').value = result;
                sheet.ActiveSheet.Range("G1").Select();
                sheet.ActiveWindow.ScrollColumn = sheet.ActiveCell.Column;
                break;
            case 0:
                $get('<%=Search2.FindControl("txtDailyInputYear").ClientID %>').value = result;
                if ('<%=Me.Session(Me.SessionID & "SF_DisplayYear") %>' == '') {
                    sheet.ActiveSheet.Range("W1").Select();
                }
                else {
                    sheet.ActiveSheet.Range(StartColumn).Select();
                }
                sheet.ActiveWindow.ScrollColumn = sheet.ActiveCell.Column;
                break;
            case 1:
                $get('<%=Search2.FindControl("txtDailyInputYear").ClientID %>').value = result;
                sheet.ActiveSheet.Range("AN1").Select();
                //sheet.ActiveSheet.Range("V1").Select();
                sheet.ActiveWindow.ScrollColumn = sheet.ActiveCell.Column;
                break;
            case 2:
                $get('<%=Search2.FindControl("txtDailyInputYear").ClientID %>').value = result;
                sheet.ActiveSheet.Range("BB1").Select();
                //sheet.ActiveSheet.Range("AK1").Select();
                sheet.ActiveWindow.ScrollColumn = sheet.ActiveCell.Column;
                break;
            default:
                alert("It's out of range!");
        }
    }

}

function cloneListPrice(value) {
    //複製值到右列

    var sheet = $get('WF_Spreadsheet1');

    //僅處理 list price 列且欄位 >= V 且要為 FCST   
    if (sheet.range('E' + sheet.ActiveCell.Row) != 'List Price') {
        return;
    }
    else if (sheet.ActiveCell.Column < sheet.Range(StartColumn).Column)//原V1    
    {
        return;
    }
    else if (sheet.cells(3, sheet.ActiveCell.Column) != 'FCST') {
        return;
    }

    var pricecell = sheet.ActiveCell.cells(1, 1);

    for (var i = 0; i < 200; i++) {
        pricecell = pricecell.cells(1, 2);

        //不可有公式且為FCST
        //if (pricecell.formula != '') continue;        
        var flagcell = sheet.cells(3, pricecell.Column);
        if (flagcell != 'FCST') continue;

        pricecell.value = value;
        pricecell.Interior.Color = 'Red';
    }
}

function OpenInCenter(width, height) {
    var left = (screen.width - width) / 2;
    var top = (screen.height - height) / 2;
    var params = 'width=' + width + ', height=' + height;
    params += ', top=' + top + ', left=' + left;
    return params;
}

function <%=Me.ClientID %>js_LoadCompleted(sheetid) {  
    $get(sheetid).activeSheet.protection.enabled = false;
    $get(sheetid).ActiveSheet.Columns.AutoFit();
    var ReportMode = '<%= Me.Search2.ReportMode %>';
    if (ReportMode == '2' || ReportMode == '3') //2:Gross;3:Act
    {
        $get(sheetid).activeSheet.cells.locked = true;
    }

    $get(sheetid).ActiveWindow.ActiveSheet.Protection.Enabled = true;

    MaxRow = $get(sheetid).ActiveSheet.UsedRange.Rows.Count
    var sfRange = $get('BK_Spreadsheet1').Range("B3:B" + MaxRow);
    var sfFromRange = $get(sheetid).Range("B3:B" + MaxRow);
    sfRange.value = sfFromRange.value;
    //sfFromRange.Copy();
    //sfRange.Paste();
}

function <%=Me.ClientID %>SF_GetMemo() {
        //有註解欄位才取資料
        var txtNotes = $get('<%=Search2.FindControl("txtNotes").ClientID %>');
        var btnUpload = $get('<%=Search2.FindControl("btnUpload").ClientID %>');
        //if (txtNotes == undefined || '<%= Me.Search2.ReportMode %>'=='1') return;//1:Meeting
        if (txtNotes == undefined) return;//1:Meeting
        var sheet = $get('WF_Spreadsheet1');
        var TargetCell = sheet.ActiveCell;
        var TopicCell = sheet.cells(2, TargetCell.column);
        var WeekCell = sheet.cells(3, TargetCell.column);
        var LevelNameCell = sheet.cells(TargetCell.row, 1);
        //FCST、ACT才取Memo
        if ((TopicCell.value == 'FCST' || TopicCell.value == 'ACT') && LevelNameCell.value == 'SKU' && WeekCell.value != 'YTD') {
            btnUpload.disabled = false;
            txtNotes.disabled = false;
            var SapCodeRow = 0;
            var SkuTypeCell = sheet.cells(TargetCell.row, 5);
            var sf = new SFMemo();
            var SkuTypeCellValue = String(SkuTypeCell.value);

            SapCodeRow = TargetCell.row;
            switch (SkuTypeCellValue) {
                case 'S':
                    SkuTypeCellValue = "S";
                    break;
                case 'N':
                    SkuTypeCellValue = "N";
                    break;
                case 'P':
                    SkuTypeCellValue = "P";
                    break;
                case 'PBOM':
                    SkuTypeCellValue = "PBOM";
                    break;
                case 'TTL Qty':
                    SkuTypeCellValue = "TTL";
                    break;
                case 'TTL Qty Y-1':
                    SkuTypeCellValue = "TTL(Y-1)";
                    break;
                case 'LSP':
                    SkuTypeCellValue = "ListP";
                    break;
                case 'STD':
                    SkuTypeCellValue = "STD";
                    break;
                case 'Gross(K)':
                    SkuTypeCellValue = "Gross";
                    break;
                case 'Gross(K) Y-1':
                    SkuTypeCellValue = "Gross(Y-1)";
                    break;
                case 'FM Base':
                    SkuTypeCellValue = "BL";
                    break;
                case 'FM New':
                    SkuTypeCellValue = "Launch";
                    break;
                case 'FM Promo':
                    SkuTypeCellValue = "Promo";
                    break;
                case 'FM PBOM':
                    SkuTypeCellValue = "FM_PBOM";
                    break;
                case 'FM TTL Qty':
                    SkuTypeCellValue = "FM_TTL";
                    break;
                case 'Gap':
                    SkuTypeCellValue = "Gap";
                    break;
                default:
                    txtNotes.value = "";
                    btnUpload.disabled = true;
                    txtNotes.disabled = true;
                    return;
            }
            sf.SkuType = SkuTypeCellValue;
            sf.ViewPoint = '<%= Me.ViewPoint %>';

        var SapCodeCell = sheet.cells(SapCodeRow, 2);
        var MonthCell = sheet.cells(3, TargetCell.column);
        sf.SapCode = SapCodeCell.value.replace('<%= MyObj.GetAreaCode() %>', '');

        var d = new Date(MonthCell.value);
        var ChannelCell = sheet.cells(1, TargetCell.column - d.getMonth());
        sf.ChannelID = GetChannelID(ChannelCell.value);

        if (TopicCell.value == 'FCST') {
            sf.MonthCode = '<%= Me.SFModel.SF_MonthCode %>';
            var now = new Date('<%=Me.SFModel.SF_Year %>', 1, 1);
            sf.MonIndex = (d.getFullYear() - now.getFullYear()) * 12 + d.getMonth() + 1;//js的月份是從0起算的，0~11共12個月
        }
        else//ACT
        {
            sf.MonthCode = String(d.getFullYear()) + 'A';
            sf.MonIndex = d.getMonth() + 1;//js的月份是從0起算的，0~11共12個月
        }

        BLSService.GetSFMemoV2(sf,<%=Me.ClientID %>SF_ShowGetMemo);
    }
    else {
        txtNotes.value = "";
        btnUpload.disabled = true;
        txtNotes.disabled = true;
    }
}

function left(str, num) {
    return str.substring(0, num)
}

function right(str, num) {
    return str.substring(str.length - num, str.length)
}

function GetChannelID(ChannelText) {
    var hf_ChannelString = $get('<%=hf_ChannelString.ClientID%>');
    var chTextArray = hf_ChannelString.value.split(";;");
    for (chText in chTextArray) {
        if (chTextArray[chText].indexOf(ChannelText) != -1) {
            var chArray = chTextArray[chText].split("__");
            return chArray[1];
        }
    }
    return "";
}

function <%=Me.ClientID %>SF_ShowGetMemo(arg) {
        var txtNotes = $get('<%=Search2.FindControl("txtNotes").ClientID %>');
    txtNotes.value = arg;
}

function <%=Me.ClientID %>SF_SaveMemo() {
        var txtNotes = $get('<%=Search2.FindControl("txtNotes").ClientID %>');

        if (txtNotes.value.length >= 1000) {
            alert('Comments is too long!!(Length:1000)');
            return;
        }

        var sheet = $get('WF_Spreadsheet1');
        var TargetCell = sheet.ActiveCell;
        var SapCodeRow = 0;
        var SkuTypeCell = sheet.cells(TargetCell.row, 5);
        var sf = new SFMemo();
        var SkuTypeCellValue = String(SkuTypeCell.value);
        var TopicCell = sheet.cells(2, TargetCell.column);
        var WeekCell = sheet.cells(3, TargetCell.column);
        var LevelNameCell = sheet.cells(TargetCell.row, 1);
        //FCST、ACT才取Memo
        if ((TopicCell.value == 'FCST' || TopicCell.value == 'ACT') && LevelNameCell.value == 'SKU' && WeekCell.value != 'YTD') {
            SapCodeRow = TargetCell.row;
            switch (SkuTypeCellValue) {
                case 'S':
                    SkuTypeCellValue = "S";
                    break;
                case 'N':
                    SkuTypeCellValue = "N";
                    break;
                case 'P':
                    SkuTypeCellValue = "P";
                    break;
                case 'PBOM':
                    SkuTypeCellValue = "PBOM";
                    break;
                case 'TTL Qty':
                    SkuTypeCellValue = "TTL";
                    break;
                case 'TTL Qty Y-1':
                    SkuTypeCellValue = "TTL(Y-1)";
                    break;
                case 'LSP':
                    SkuTypeCellValue = "ListP";
                    break;
                case 'STD':
                    SkuTypeCellValue = "STD";
                    break;
                case 'Gross(K)':
                    SkuTypeCellValue = "Gross";
                    break;
                case 'Gross(K) Y-1':
                    SkuTypeCellValue = "Gross(Y-1)";
                    break;
                case 'FM Base':
                    SkuTypeCellValue = "BL";
                    break;
                case 'FM New':
                    SkuTypeCellValue = "Launch";
                    break;
                case 'FM Promo':
                    SkuTypeCellValue = "Promo";
                    break;
                case 'FM PBOM':
                    SkuTypeCellValue = "FM_PBOM";
                    break;
                case 'FM TTL Qty':
                    SkuTypeCellValue = "FM_TTL";
                    break;
                case 'Gap':
                    SkuTypeCellValue = "Gap";
                    break;
                default:
                    txtNotes.value = "";
                    btnUpload.disabled = true;
                    txtNotes.disabled = true;
                    return;
            }
            sf.SkuType = SkuTypeCellValue;
            var SapCodeCell = sheet.cells(SapCodeRow, 2);
            var MonthCell = sheet.cells(3, TargetCell.column);
            sf.SapCode = SapCodeCell.value.replace('<%= MyObj.GetAreaCode() %>', '');
        sf.Memo = txtNotes.value;
        sf.ViewPoint = '<%= Me.ViewPoint %>';

        var d = new Date(MonthCell.value);
        var ChannelCell = sheet.cells(1, TargetCell.column - d.getMonth());
        sf.ChannelID = GetChannelID(ChannelCell.value);

        if (TopicCell.value == 'FCST') {
            sf.MonthCode = '<%= Me.SFModel.SF_MonthCode %>';
            var now = new Date('<%=Me.SFModel.SF_Year %>', 1, 1);
            sf.MonIndex = (d.getFullYear() - now.getFullYear()) * 12 + d.getMonth() + 1;//js的月份是從0起算的，0~11共12個月
        }
        else//ACT
        {
            sf.MonthCode = String(d.getFullYear()) + 'A';
            sf.MonIndex = d.getMonth() + 1;//js的月份是從0起算的，0~11共12個月
        }

        var OldStatus = TargetCell.locked;
        TargetCell.locked = false;
        if (txtNotes.value != '') {
            TargetCell.Borders.LineStyle = 1;
            TargetCell.Borders.Weight = 2;
            TargetCell.Borders.Color = 'Red';
        }
        else {
            TargetCell.Borders.Color = '';
        }
        TargetCell.locked = OldStatus;
        BLSService.SaveSFMemoV2(sf,<%=Me.ClientID %>SF_ShowSaveMemo);
    }
    else {
        txtNotes.value = "";
        btnUpload.disabled = true;
        txtNotes.disabled = true;
    }
}

function <%=Me.ClientID %>SF_ShowSaveMemo(arg) {
        alert(arg);
    }

</script>

<script type="text/javascript" language="JavaScript">
    var cX = 0; var cY = 0; var rX = 0; var rY = 0;
    function UpdateCursorPosition(e) { cX = e.pageX; cY = e.pageY; }
    function UpdateCursorPositionDocAll(e) { cX = event.clientX; cY = event.clientY; }
    //if(document.all) { document.onmousemove = UpdateCursorPositionDocAll; }
    //else { document.onmousemove = UpdateCursorPosition; }
    function AssignPosition(d) {
        if (self.pageYOffset) {
            rX = self.pageXOffset;
            rY = self.pageYOffset;
        }
        else if (document.documentElement && document.documentElement.scrollTop) {
            rX = document.documentElement.scrollLeft;
            rY = document.documentElement.scrollTop;
        }
        else if (document.body) {
            rX = document.body.scrollLeft;
            rY = document.body.scrollTop;
        }
        if (document.all) {
            cX += rX;
            cY += rY;
        }
        d.style.left = (cX + 5) + "px";
        d.style.top = (cY - 200) + "px";
    }
    function HideContent(d) {
        if (d.length < 1) { return; }
        document.getElementById(d).style.display = "none";
    }

    function ShowContent(d, url) {
        return//return
        var dd = document.getElementById(d);
        AssignPosition(dd);
        dd.style.display = "block";
        var Myiframe = $get('IFRAME1');
        Myiframe.src = url;
    }

    function ReverseContentDisplay(d) {
        if (d.length < 1) { return; }
        var dd = document.getElementById(d);
        AssignPosition(dd);
        if (dd.style.display == "none") { dd.style.display = "block"; }
        else { dd.style.display = "none"; }
    }

</script>

<div id="divStock" style="display: none; overflow: auto; z-index: 9999; left: 8px; width: 500px; position: absolute; top: 8px; height: 500px">
    <iframe scrolling="no" frameborder="0" style="background-color: #4E333B" width="100%"
        height="100%" id="IFRAME1"></iframe>
</div>

<script type="text/vbscript">
Sub WF_Spreadsheet1_LoadCompleted()
    Call <%=Me.ClientID %>js_LoadCompleted("WF_Spreadsheet1")
End Sub

'OK,鍵盤上下左右事件
Sub WF_Spreadsheet1_KeyDown(ByVal KeyCode,ByVal Shift)  
    '紀錄現在的值
    set hf_NowValue = document.getElementById("<%= hf_NowValue.ClientID %>")
    set WorkSheet_SS = document.getElementById("WF_Spreadsheet1")
    hf_NowValue.value = WorkSheet_SS.ActiveCell.Value  
    call <%=Me.ClientID %>SF_GetMemo()
End Sub

'OK,滑鼠點擊事件
Sub WF_Spreadsheet1_Click()
    call <%=Me.ClientID %>SF_GetMemo()
End Sub

'複製貼上
Sub WF_Spreadsheet1_SheetChange(ByVal Sh, ByVal Target)
    On error resume Next 
    set sheet = document.getElementById("WF_Spreadsheet1")
    sheet.EnableEvents = false
    
    '若為單一Cell,則有修改才做動作
    if sheet.Selection.count=1 then
        set hf_NowValue = document.getElementById("<%= hf_NowValue.ClientID %>")
        if Target.Locked<>true then
            if Cstr(Target.value)<>Cstr(hf_NowValue.value) then
                sheet.ActiveCell.Interior.Color = vbRed
                call <%= Me.ClientID %>AddSaveIndex(sheet.ActiveCell.Row,sheet.ActiveCell.Column)
            end if
        end if
    elseif sheet.Selection.count>1 then
        set MySelection=sheet.Selection
        For Each rng In sheet.Selection
            if rng.Locked<>true then
                rng.Interior.Color = vbRed
                rng.Select()
                call <%= Me.ClientID %>AddSaveIndex(sheet.ActiveCell.Row,sheet.ActiveCell.Column)
            end if
        Next
        MySelection.select()
    end if   
    sheet.EnableEvents = true
    If err.number<>0 then   
        err.Raise 6   ' Raise an overflow error.
        MsgBox ("Error # " & CStr(err.Number) & " " & err.Description)
        err.Clear      ' Clear the error.
    End If 
End Sub

    Sub WF_Spreadsheet1_SelectionChange()
        set WorkSheet_SS = document.getElementById("WF_Spreadsheet1")
        Dim Row 
	    Dim Col
	    MaxCol = WorkSheet_SS.ActiveSheet.UsedRange.Columns.Count 
        MaxRow = WorkSheet_SS.ActiveSheet.UsedRange.Rows.Count 
        sumvalue = 0 
        sumcount = 0 
        colType = "Number"
        
        for Each Row In WorkSheet_SS.Selection.Rows 
		    if Row.row > MaxRow then 
		        exit for 
            end if 
            for Each Col In WorkSheet_SS.Selection.Columns 
	    	    if Col.column > MaxCol then 
	 	 	        exit for 
                end if 
                if VarType(WorkSheet_SS.ActiveSheet.Cells(Row.row,Col.column).value)>=2 and VarType(WorkSheet_SS.ActiveSheet.Cells(Row.row,Col.column).value)<=5 then 
	                if sumcount=0 and InStr(WorkSheet_SS.ActiveSheet.Cells(Row.row,Col.column).NumberFormat,"%")<>0 then
	                    colType = "Percent"
	                end if
	                if colType = "Percent" then 
	                    sumvalue = sumvalue + (WorkSheet_SS.ActiveSheet.Cells(Row.row,Col.column).value * 100)
	                else
	                    sumvalue = sumvalue + WorkSheet_SS.ActiveSheet.Cells(Row.row,Col.column).value 
	                end if
	                sumcount = sumcount + 1
                end if 
            next 
        next 

        if sumcount<>0 Then
            if colType = "Percent" then
                avg = Round(sumvalue / sumcount,2)
            else
                avg = Round(sumvalue / sumcount,0)
            end if
        else
            avg = 0
        end if
        if colType = "Percent" then
            window.status = "Average: " & FormatNumber(avg,2) & "%" & "  Count: " & FormatNumber(sumcount,0) & "  Sum: " & FormatNumber(sumvalue,2) & "%"
        else
            window.status = "Average: " & FormatNumber(avg,0) & "  Count: " & FormatNumber(sumcount,0) & "  Sum: " & FormatNumber(sumvalue,0)
        end if
        
    End Sub 
</script>

<script type="text/javascript">
    function FormatNumber(srcstr, nafterdot) {
        var srcstr, nafterdot;
        var resultstr, nten;
        srcstr = "" + srcstr + "";
        strlen = srcstr.length;
        dotpos = srcstr.indexOf(".", 0);
        if (dotpos == -1) {
            resultstr = srcstr + ".";
            for (i = 0; i < nafterdot; i++) {
                resultstr = resultstr + "0";
            }
            return resultstr;
        }
        else {
            if ((strlen - dotpos - 1) >= nafterdot) {
                nafter = dotpos + nafterdot + 1;
                nten = 1;
                for (j = 0; j < nafterdot; j++) {
                    nten = nten * 10;
                }
                resultstr = math.round(parsefloat(srcstr) * nten) / nten;
                return resultstr;
            }
            else {
                resultstr = srcstr;
                for (i = 0; i < (nafterdot - strlen + dotpos + 1) ; i++) {
                    resultstr = resultstr + "0";
                }
                return resultstr;
            }
        }
    }
</script>

<script type="text/javascript">

    data = new Array();

    function <%=Me.ClientID %>saveData() {
        if (data.length == 0) {
            alert("No data changed.");
            return;
        }

        var sheet = $get('WF_Spreadsheet1');

        //僅上傳有異動的資料行
        for (var i = 0; i < data.length; i++) {
            var sf = data[i];
            sf.SapCode = sheet.Range("B" + sf.RefIndex).value.replace('<%= MyObj.GetAreaCode() %>', '');
            switch (sheet.Range("E" + sf.RefIndex).value) {
                case "S":
                    sf.SkuType = "S"
                    break;
                case "N":
                    sf.SkuType = "N"
                    break;
                case "P":
                    sf.SkuType = "P"
                    break;
            }

            var MonthCell = sheet.cells(3, sf.RefColIndex);
            var d = new Date(MonthCell.value);
            var ChannelCell = sheet.cells(1, sf.RefColIndex - d.getMonth());
            sf.Channel = GetChannelID(ChannelCell.value);
            sf.ViewPoint = '<%=Me.ViewPoint %>';

            var currmon = 1;
            var now = new Date('<%=Me.SFModel.SF_Year %>', 1, 1);
                currmon = (d.getFullYear() - now.getFullYear()) * 12 + d.getMonth() + 1;//js的月份是從0起算的，0~11共12個月

                sf['Mon' + currmon] = sheet.cells(sf.RefIndex, sf.RefColIndex).value;
            //用cell顏色判斷有無修改
                if (sheet.cells(sf.RefIndex, sf.RefColIndex).Interior.Color == '255') {
                    sf['Mon' + currmon + 'Change'] = 'Y';
                    sheet.cells(sf.RefIndex, sf.RefColIndex).Interior.Color = '#FFFFCC';//清除紅色標記
                }
            }

            SFService.SaveData(data, '<%= Me.SessionID %>', <%=Me.ClientID %>OnComplete);
        data = new Array();
    }

    //紀錄哪一Cell有異動
    function <%=Me.ClientID %>AddSaveIndex(rowIndex, colIndex) {
        //確認此 index 是否已被儲存
        for (var i = 0; i < data.length; i++) {
            if (data[i].RefIndex == rowIndex && data[i].RefColIndex == colIndex) return;
        }

        var sf = new SFReport();

        sf.RefIndex = rowIndex;
        sf.RefColIndex = colIndex;
        data[data.length] = sf;
    }

    function <%=Me.ClientID %>OnComplete(arg) {
        alert(arg);
    }

    function <%=Me.ClientID %>SF_FocusFind() {
        if (event.keyCode == 13) {
            $get('<%=Search2.FindControl("btnFindProd").ClientID %>').focus();
            return false;
        }
    }
</script>

<My:ProductHierarchyControl ID="ProductHierarchyControl1" runat="server" />
<br />
<asp:PlaceHolder ID="pl1" runat="server" Visible="false">
    <div style="background-color: #351D26">
        <fieldset id="pnlData" runat="server" style="border-color: #4E333B;">
            <legend class="white2">
                <asp:Literal ID="Literal1" runat="server" Text="<%$ Resources:pnlData.GroupingText%>" />
            </legend>
            <MyReport:Search2View ID="Search2" runat="server">
                <NormalSearchTemplate>
                    <table align="left" width="100%" border="0" cellspacing="0">
                        <tr>
                            <td align="left">
                                <table align="left" width="100%" border="0" cellspacing="0">
                                    <tr>
                                        <td align="left">
                                            <div style="Display: None">
                                                <asp:Label ID="lblYear" runat="server" meta:resourcekey="lblYear"></asp:Label>
                                                <input type="button" id="btnPrev" class="button" runat="server" value="<%$ Resources:btnPrev.Text %>"
                                                    enabled='<%# ProductHierarchyControl1.DisplayYear = MyObj.GetDDLSelectAllItem.Value %>'
                                                    onclick='<%# Me.ClientID + "YearNext(-1);return false;" %>' />
                                                <asp:TextBox ID="txtDailyInputYear" runat="server" Width="30px" Enabled="false"></asp:TextBox>
                                                <input type="button" id="btnNext" class="button" runat="server" value="<%$ Resources:btnNext.Text %>"
                                                    enabled='<%# ProductHierarchyControl1.DisplayYear = MyObj.GetDDLSelectAllItem.Value %>'
                                                    onclick='<%# Me.ClientID + "YearNext(1);return false;" %>' />
                                                <input type="button" id="btnGrossSales" visible="false" class="button2" runat="server"
                                                    onclick="openSpecWindow('GrossSales'); return false;" value="<%$ Resources:btnGrossSales.Text %>" />
                                                <input type="button" id="btnACT" visible="false" class="button2" runat="server" onclick="openSpecWindow('Act'); return false;"
                                                    value='<%# Session(Me.SessionID & "SF_Year") - 1 & " Act" %>' />
                                            </div>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                            <td align="left"></td>
                        </tr>
                        <tr>
                            <td align="left" colspan="2">
                                <asp:Label ID="lblFindProd" runat="server" meta:resourcekey="lblFindProd"></asp:Label>
                                <asp:TextBox ID="txtFindProd" OnKeyPress='<%# Me.ClientID + "SF_FocusFind();" %>'
                                    runat="server"></asp:TextBox>
                                <input type="button" id="btnFindProd" class="button" runat="server" value="<%$ Resources:btnFindProd.Text %>"
                                    onclick='<%# Me.ClientID + "SF_FindProd();return false;" %>' />
                                <input type="button" id="btnPercentage" style="width: 15px" class="button" runat="server"
                                    value="<%$ Resources:btnPercentage.Text %>" onclick="openSpecWindow('Percentage');" />
                                <asp:Button ID="btnRefreshSF" runat="server" Visible="false" Text="Refresh" OnClick="btnRefreshSF_Click" />
                                <asp:Label ID="lblNotes" runat="server" meta:resourcekey="lblNotes"></asp:Label>
                                <asp:TextBox ID="txtNotes" TextMode="MultiLine" Rows="2" Columns="38" runat="server"
                                    Width="375px"></asp:TextBox>
                                <input type="button" id="btnUpload" class="button" runat="server" value="<%$ Resources:btnUpload.Text %>"
                                    onclick='<%# Me.ClientID + "SF_SaveMemo();return false;" %>' />
                                <input type="button" id="btnSave" class="button" runat="server" onclick='<%# Me.ClientID + "saveData()"%>'
                                    value="<%$ Resources:btnSave.Text %>" />
                            </td>
                        </tr>
                    </table>
                </NormalSearchTemplate>
            </MyReport:Search2View>
        </fieldset>
    </div>
    <asp:HiddenField ID="hf_FindProd" runat="server" />
    <asp:HiddenField ID="hf_MemoData" runat="server" />
    <asp:HiddenField ID="hf_NowAddress" runat="server" />
    <asp:HiddenField ID="hf_NowValue" runat="server" />
    <asp:HiddenField ID="hf_YearNow" runat="server" />
    <asp:HiddenField ID="hf_Unit" runat="server" />
    <asp:HiddenField ID="hf_Gross" runat="server" />
    <asp:HiddenField ID="hf_ColumnCount" runat="server" />
    <asp:HiddenField ID="hf_SapCode" runat="server" />
    <asp:HiddenField ID="hf_TargetRow" runat="server" />
    <asp:HiddenField ID="hf_TargetColumn" runat="server" />
    <asp:HiddenField ID="hf_ChannelString" runat="server" />
    <object id="WF_Spreadsheet1" classid="CLSID:0002E559-0000-0000-C000-000000000046"
        width="100%" height="515px" standby="Loading">
        <param name="DataType" value="XMLURL" />
        <param name="XMLURL" value="<%= Me.FilePathClient%>" />
        <param name="AutoFit" value="0" />
    </object>
    <object id="BK_Spreadsheet1" classid="CLSID:0002E559-0000-0000-C000-000000000046"
        width="0%" height="0px" standby="Loading">
    </object>
</asp:PlaceHolder>

<script type="text/javascript">
    if ($get('WF_Spreadsheet1') != undefined && '<%= Me.SFModel.SF_Lock %>' == 'True') {
        $get('WF_Spreadsheet1').activeSheet.cells.locked = true;
        $get('WF_Spreadsheet1').activeSheet.protection.enabled = true;
    }
</script>

<%--    </ContentTemplate>
</asp:UpdatePanel>--%>



